🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

waterline-jsonapi

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

waterline-jsonapi

Create JSONAPI compliant payloads from Waterline blueprints.

0.3.21
latest
Source
npm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

waterline-jsonapi

Build Status Coverage Status Code Climate Known Vulnerabilities

Create JSON API compliant payloads from Waterline blueprints and query results and get a promise in return.

npm i waterline-jsonapi --save

Usage

You need only your query results and your collection to get started. Assuming the example user and pet collections.

const Waterline_JSONAPI = require("waterline-jsonapi")

// The query
User
  .find()
  .populate("pets")

  // Create a JSON API payload from the results.
  .then(user_and_pets => {
    const jsonapi = new Waterline_JSONAPI(user_and_pets, User).generate()
    reply(jsonapi)
  })

// Or with a Promise

User
  .find()
  .populate("pets")

  // Create a JSON API payload from the results.
  .then(user_and_pets => {
    new Waterline_JSONAPI(user_and_pets, User).generate(true) // Note: the true here.

      // Reply with your data.
      .then(payload => reply(payload))

      // If there was an unlikely error, you can catch here.
      .catch(error => reply(error))
  })

The above will reply with a valid JSONAPI payload, the same works by passing in an Error or an object with is_error: true.

Links are retrieved from your collections if they have any of the following functions.

All links functions are passed a single resource object and a meta object passed into the constructor.

get_self_link(resource, meta)
get_next_link(resource, meta)
get_last_link(resource, meta)
get_related_link(resource, meta)

Inside of the meta object is a context variable passed in by this library, it is a string and one of these values:

"related"
"single"
"list"

For you to return the appropriate link.

Meta

You can define metadata on your collection in the get_meta function. This function takes no arguments and should return an object.

API

This version is a 100% rebuild from the ground up and all previous API methods have been deprecated and removed as they were invalid.

MIT License © New World Code

Keywords

waterline

FAQs

Package last updated on 29 Mar 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts